<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>    
    <div id="app">      
        <p>单价：{{price}}</p>
        <p>数量：{{count}}</p>
        <input type="button" value="  +  " @click="changeCount" >
        <input type="button" value="  涨价  " @click="changePrice" >
        <p>小计：{{money}}</p>
        <input type="button" value="  停止count侦听  " @click="stopWatchCount" >
        <input type="button" value="  停止price侦听  " @click="stopWatchPrice" >
        
    </div>
</body>
</html>

<script src="./js/vue.global.js"></script>
<script>    

     const {createApp,ref,reactive,watch,watchEffect} = Vue;

    let app = createApp({
        setup(){
            let price = ref(25);
            let count = ref(1);
            let money = ref(0);

            let stopHandleCount = watchEffect(()=>{
                money.value = price.value*count.value
            })

            let stopHandlePrice = watch(price,()=>{
                money.value = price.value*count.value
            })
            
            function changeCount(){
                count.value++;
            }

            function changePrice(){
                price.value++;
            }

            function stopWatchCount(){
                stopHandleCount();
            }

            function stopWatchPrice(){
                stopHandlePrice();
            }
            
            return {
               price,count,money,changeCount,changePrice,stopWatchCount,stopWatchPrice
            }
        }
    })

    app.mount("#app");

</script>